<html>

<head>
    <meta charset="utf-8">
    <title> 编辑用户角色</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/${BasePath}/static/css/headpic.css" media="all" />
    <link rel="stylesheet" href="/${BasePath}/static/layui/css/layui.css" media="all" type="text/css">
    <link rel="stylesheet" href="/${BasePath}/static/css/public.css" media="all" type="text/css"> </head>

<body class="childrenBody">
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
	  <legend>配置角色</legend>
	</fieldset>
    <form id="infoForm" class="layui-form" lay-filter="example">
        <div class="layui-col-md6 layui-col-xs12">
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-block">
                    <input type="text" value="${Suser.username!''}" disabled class="layui-input layui-disabled"> </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">姓名</label>
                <div class="layui-input-block">
                    <input type="text" value="${info.name!''}" disabled class="layui-input layui-disabled"> </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">联系电话</label>
                <div class="layui-input-block">
                    <input type="text" value="${info.phone!''}" disabled class="layui-input layui-disabled"> </div>
            </div>           
            <div class="layui-form-item">
                <label class="layui-form-label">设置角色</label>
                      <div class="layui-input-block" id="test" lay-filter="test"> </div>
            </div>                                   
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" type="button" lay-filter="form">立即提交</button>
                </div>
            </div>
        </div>
    </form>
    <script type="text/javascript" src="/${BasePath}/static/layui/layui.js" charset="utf-8" ></script>
    <script type="text/javascript" src="/${BasePath}/static/js/common/jquery-2.1.0.min.js"></script>
    <script type="text/javascript" src="/${BasePath}/static/js/common/ajaxfileupload.js" charset="utf-8" ></script>
    <script type="text/javascript" src="/${BasePath}/static/js/common/popup.js"></script>
    <script type="text/javascript">
    layui.config({
        base : "/${BasePath}/static/layui/"
    }).extend({
        'selectPlus' : 'selectPlus'
    })
    layui.use(['form', 'layedit', 'laydate','selectPlus'], function() {
        var form = layui.form,
            layer = layui.layer,
            selectPlus = layui.selectPlus;
        // 多选
        var test = selectPlus.render({
          el: '#test',
          url: "/${BasePath}/power/queryRoleMap",
          valueName: "name",
          <#if values??>
          values:${values!''},
          </#if>
          valueSeparator: ","
        });
        form.on('submit(form)', function() {
            var obj = test.getChecked();
            if(obj.data==""){
            	layer.msg('请选择角色！');
            	return;
            }
            
            var temp = obj.data;
            var roleId=new Array();
            for(var i=0;i<temp.length;i++){
            	roleId.push(temp[i].id);
            }
            $.ajax({
                cache: true,
                type: "POST",
                url: "/${BasePath}/power/saveUserRole",
                data: {"id":${Suser.id!'0'},"roleId":roleId},
                async: false,
                error: function(request) {
                    layer.msg('系统错误！');
                },
                success: function(data) {
                	if(data.code=="1"){
                		layer.msg(data.msg,{time:1000},function(){   //提示框设定显示2秒
                			window.location.href="/${BasePath}/power/userList"	
                		})	
                	}
                	
                }
            });
            
       });
    });
    
    
    </script>
</body>

</html>